home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / H-I / HypertalkTools.cpt / Importer / card_2888.txt < prev    next >
Text File  |  1989-02-26  |  10KB  |  359 lines

  1. -- card: 2888 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2711
  5. -- name: 
  6.  
  7.  
  8. -- part 4 (field)
  9. -- low flags: 80
  10. -- high flags: 0004
  11. -- rect: left=11 top=190 right=310 bottom=386
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 3
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: warning
  20.  
  21.  
  22. -- part 3 (button)
  23. -- low flags: 80
  24. -- high flags: A003
  25. -- rect: left=318 top=274 right=298 bottom=379
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 0 / 0
  28. -- text alignment: 1
  29. -- font id: 0
  30. -- text size: 12
  31. -- style flags: 0
  32. -- line height: 16
  33. -- part name: OK
  34. ----- HyperTalk script -----
  35. on mouseUp
  36.   hide card field "warning"
  37.   hide card button "ok"
  38. end mouseUp
  39.  
  40.  
  41.  
  42. -- part 5 (field)
  43. -- low flags: 80
  44. -- high flags: 0002
  45. -- rect: left=12 top=31 right=184 bottom=385
  46. -- title width / last selected line: 0
  47. -- icon id / first selected line: 0 / 0
  48. -- text alignment: 0
  49. -- font id: 3
  50. -- text size: 12
  51. -- style flags: 0
  52. -- line height: 16
  53. -- part name: display
  54.  
  55.  
  56. -- part 76 (button)
  57. -- low flags: 00
  58. -- high flags: A000
  59. -- rect: left=407 top=86 right=149 bottom=480
  60. -- title width / last selected line: 0
  61. -- icon id / first selected line: 1517 / 1517
  62. -- text alignment: 1
  63. -- font id: 0
  64. -- text size: 12
  65. -- style flags: 0
  66. -- line height: 16
  67. -- part name: Import 
  68. ----- HyperTalk script -----
  69. --File Importer Button
  70. --Copyright ¬© 1987 Stephen Michel 1027 Pomona, Albany, CA 94706
  71. --If you like it, send me what it's worth
  72.  
  73. on mouseUp
  74.   global inFile
  75.   global error
  76.   newStack
  77.   show message box at 33,296
  78.   getFile
  79.   if error is not empty then
  80.     exit mouseUp
  81.   end if
  82.   goodFile
  83.   if error is not empty then
  84.     exit mouseUp
  85.   end if
  86.   createStruct
  87.   importText
  88.   choose browse tool
  89. end mouseUp
  90.  
  91. on newStack
  92.   global inFile
  93.   global error
  94.   -- Creates the new stack
  95.   doMenu New Stack...
  96. end newStack
  97.  
  98. on getFile
  99.   global inFile
  100.   global error
  101.   -- finds the file to import from
  102.   ask "Read from what file?"
  103.   if it is empty then
  104.     put "true" into error
  105.   else
  106.     put empty into error
  107.     put it into inFile
  108.   end if
  109. end getFile
  110.  
  111. on createStruct
  112.   -- right now, this just creates a structure for a tab-delimited file
  113.   global inFile
  114.   global error
  115.   global countFields
  116.   put 0 into countFields
  117.   open file inFile
  118.   put "Now analyzing the structure & counting fields..."
  119.   put "dummy" into it
  120.   -- simply loops through the first record until it hits a return
  121.   -- and adds one to countFields every time it finds a tab
  122.   repeat until it is empty
  123.     read from file inFile until tab
  124.     add 1 to countFields
  125.     if it contains return then
  126.       exit repeat
  127.     end if
  128.   end repeat
  129.   close file inFile
  130.   put "There are " & countFields & " fields in the file"
  131.   domenu "background"
  132.   open file inFile
  133.   repeat with x = 1 to countFields - 1
  134.     read from file inFile until tab
  135.     ask "Please type a name for field" && x with it
  136.     put it into fieldName
  137.     newField fieldName
  138.   end repeat
  139.   read from file inFile until return
  140.   ask "Please type a name for field" && countFields with it
  141.   put it into fieldName
  142.   newfield fieldName
  143.   domenu "background"
  144.   close file inFile
  145. end createStruct
  146.  
  147. on importText
  148.   global inFile
  149.   global error
  150.   global countFields
  151.   open file inFile
  152.   put "dummy" into it
  153.   put 1 into recNum
  154.   -- loops through the cards & fields until the end of file
  155.   -- this usually creates one or two extra cards, but it
  156.   -- was easy to code.
  157.   put the seconds into startTime
  158.   repeat until it is empty
  159.     put "Now on record #" & recNum
  160.     repeat with x = 1 to countFields -1
  161.       read from file inFile until tab
  162.       -- this line removes the tab
  163.       delete last character of it
  164.       put it into field x
  165.     end repeat
  166.     read from file inFile until return
  167.     put it into field countFields
  168.     domenu "new card"
  169.     add 1 to recNum
  170.   end repeat
  171.   put the seconds into stopTime
  172.   close file inFile
  173.   put stopTime - startTime into timeTook
  174.   divide timeTook by 60
  175.   put "Done!" && recNum && "records written" && "in" && timeTook && "minutes."
  176. end importText
  177.  
  178. on goodFile
  179.   -- checks to make sure the file exists
  180.   -- Hypercard automatically creates a new file when you
  181.   -- issue the "open" command.  So we read from the file
  182.   -- to see if there is anything in it.
  183.   -- Be sure to delete any excess files created by this.
  184.   -- You can probably type in a path name to a file, if it is not
  185.   -- in the same folder as HyperCard
  186.   global inFile
  187.   global error
  188.   open file inFile
  189.   read from file inFile until return
  190.   if it is empty then
  191.     put "That file does not exist"
  192.     put "true" into error
  193.     exit goodFile
  194.   end if
  195.   close file inFile
  196. end goodFile
  197.  
  198. on newField fieldName
  199.   put the number of background fields into numFields
  200.   put numFields + 1 into thisField
  201.   put "click where you want the field to go"
  202.   wait until the mouseClick
  203.   put the mouseLoc into here
  204.   domenu "new field"
  205.   put first item of here into right
  206.   add 150 to right
  207.   put second item of here into bottom
  208.   add 20 to bottom
  209.   put here && ","&& right && "," && bottom into thePlace
  210.   set rect of background field thisField to thePlace
  211.   set style of background field thisField to rectangle
  212.   set name of background field thisField to fieldName
  213. end newField
  214.  
  215.  
  216.  
  217.  
  218. -- part 79 (button)
  219. -- low flags: 00
  220. -- high flags: 8000
  221. -- rect: left=407 top=25 right=83 bottom=479
  222. -- title width / last selected line: 0
  223. -- icon id / first selected line: 14767 / 14767
  224. -- text alignment: 1
  225. -- font id: 0
  226. -- text size: 12
  227. -- style flags: 0
  228. -- line height: 16
  229. -- part name: About...
  230. ----- HyperTalk script -----
  231. on mouseUp
  232.   show card field "about"
  233. end mouseUp
  234.  
  235.  
  236.  
  237. -- part 81 (field)
  238. -- low flags: 01
  239. -- high flags: 0004
  240. -- rect: left=0 top=20 right=342 bottom=512
  241. -- title width / last selected line: 0
  242. -- icon id / first selected line: 0 / 0
  243. -- text alignment: 0
  244. -- font id: 3
  245. -- text size: 9
  246. -- style flags: 0
  247. -- line height: 12
  248. -- part name: about
  249. ----- HyperTalk script -----
  250. on mouseUp
  251.   hide card field "about"
  252. end mouseUp
  253.  
  254.  
  255.  
  256. -- part contents for card part 5
  257. ----- text -----
  258. 1    Frederik    Pohl    Heechee Rendezvous    Ballantine    pb    83    320    3.95    4    fic        sf    3/22/85    Might round out the Heechee saga that started in Gateway.  Read it on the plane to NYC.  Pohl is, of course, one of the very best.  Still, this novel did not move me like it should have, like Gateway did.  It tells a larger story than Gateway -- that is, it is not primarily about one individual.  And that is what made Gateway one of the best sf novels.
  259.  
  260.  
  261. -- part contents for card part 4
  262. ----- text -----
  263. That file does not exist
  264. Or is not in the current folder
  265.  
  266. -- part contents for card part 25
  267. ----- text -----
  268.  
  269.  
  270.  
  271. -- part contents for card part 26
  272. ----- text -----
  273.  
  274.  
  275.  
  276. -- part contents for card part 27
  277. ----- text -----
  278.  
  279.  
  280.  
  281.  
  282. -- part contents for card part 29
  283. ----- text -----
  284.  
  285.  
  286.  
  287. -- part contents for background part 53
  288. ----- text -----
  289. 1
  290.  
  291. -- part contents for background part 54
  292. ----- text -----
  293. Frederik
  294.  
  295. -- part contents for background part 55
  296. ----- text -----
  297. Pohl
  298.  
  299. -- part contents for background part 56
  300. ----- text -----
  301. Heechee Rendezvous
  302.  
  303. -- part contents for background part 57
  304. ----- text -----
  305. Ballantine
  306.  
  307. -- part contents for background part 58
  308. ----- text -----
  309. pb
  310.  
  311. -- part contents for background part 59
  312. ----- text -----
  313. 83
  314.  
  315. -- part contents for background part 60
  316. ----- text -----
  317. 320
  318.  
  319. -- part contents for background part 61
  320. ----- text -----
  321. 3.95
  322.  
  323. -- part contents for background part 62
  324. ----- text -----
  325. 4
  326.  
  327. -- part contents for background part 63
  328. ----- text -----
  329. fic
  330.  
  331. -- part contents for background part 65
  332. ----- text -----
  333. sf
  334.  
  335. -- part contents for background part 66
  336. ----- text -----
  337. 3/22/85
  338.  
  339. -- part contents for background part 67
  340. ----- text -----
  341. Might round out the Heechee saga that started in Gateway.  Read it on the plane to NYC.  Pohl is, of course, one of the very best.  Still, this novel did not move me like it should have, like Gateway did.  It tells a larger story than Gateway -- that is, it is not primarily about one individual.  And that is what made Gateway one of the best sf novels.
  342.  
  343.  
  344. -- part contents for card part 81
  345. ----- text -----
  346. FILE IMPORTER                                                                                        CLICK ANYWHERE TO RETURN
  347. Copyright ¬© 1987 Stephen Michel
  348. 1027 Pomona, Albany, CA 94706   If you like it, please send $10.  Thanx.
  349.  
  350. This will read any TAB DELIMITED file into a new stack, allow you to name fields to hold the data, and do some layout of the form.  It will provide a relatively complete HyperCard database that includes next, previous, and home buttons -- the rest is up to you.  
  351.  
  352. You will be asked first for the name of the new stack -- the usual Mac getfile stuff works here.  Next it will want to know the name of the text file file.  You must either type the full path name of the file, or it must be in the HyperCard folder to work.  The script will then read the file, figure out how many fields are in it and ask for the name of each field.  Each field name defaults to the data that is in that field in the first record of the file -- to help you remember what each field is, or if you have put the field names at the top, to make it easier.
  353.  
  354. LIMITATIONS:  There are many: 1) As of now, it will only read tab delimited fields, though I am working on other formats (such as mailmerge, comma delimited, SYLK, etc.). 2) All the created fields are the same size on screen.  This simplified the coding, and it shouldn't be too hard to go back and adjust them. 
  355.  
  356. CHANGES: Aside from making it more flexible in types of files it can read, it could go faster by locking the screen, so every record doesn't have to get written.  But I like to see what is going on.  You can also customize this by placing the "import" button onto a background you like better -- it is  self contained.
  357.  
  358. Clicking "cancel" in most dialogues will NOT stop the entire operation -- I haven't done all the error trapping yet.  Typing command-period will stop it, though it will leave the file open.  Type "close file" followed by the file name into the message box to close the file.  I have worked with files of up to 250 records, and it does take some time (about 10 minutes to read 200 or so records into a stack).
  359.